package com.yeziji.utils;

import cn.hutool.core.util.StrUtil;
import com.yeziji.common.CommonSymbol;

/**
 * rabbit mq 辅助工具类
 *
 * @author hwy
 * @since 2024/10/30 16:21
 **/
public class RabbitMqUtils {
    /**
     * 获取 rabbitmq 平台拼接常用键值
     *
     * @param uniqueCode 平台唯一码(client)
     * @param key        拼接键值
     * @return {@link String}
     */
    public static String getAsRabbitPlatformKey(String uniqueCode, String key) {
        boolean hasCode = StrUtil.isNotBlank(uniqueCode);
        if (hasCode) {
            return String.format("%s.%s", uniqueCode, key);
        }
        return key;
    }

    /**
     * 获取 rabbitmq 平台拼接常用键值
     *
     * @param uniqueCode 平台唯一码(client)
     * @param key        拼接键值
     * @return {@link String}
     */
    public static String getAsRabbitNotPlatformKey(String uniqueCode, String key) {
        boolean hasCode = StrUtil.isNotBlank(uniqueCode);
        if (hasCode) {
            return StrUtil.replaceFirst(key, uniqueCode + CommonSymbol.FULL_STOP, CommonSymbol.EMPTY);
        }
        return key;
    }
}
